package br.com.salao.model;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import org.apache.log4j.Logger;

import br.com.salao.session.CriptografiaBase;
import br.com.salao.util.Utils;

public class CriptografiaModel {
	
	private Logger logger =  Logger.getLogger(CriptografiaModel.class.getName());
	
	public String gerarSenhaCriptografada(String senhaOriginal) throws Exception{
		CriptografiaBase criptografiaBase = getBean();
		return criptografiaBase.gerarSenhaCriptografada(senhaOriginal);
	}
	
	public boolean isSenhaValida(String senhaDigitada , String senhaArmazenada) throws Exception{
		CriptografiaBase criptografiaBase = getBean();
		return criptografiaBase.isSenhaValida(senhaDigitada, senhaArmazenada);
	}
	
    public CriptografiaBase getBean() throws Exception {
    	
    	logger.debug(":: CriptografiaModel :: getBean() :: ");
    	
        Properties prop = Utils.getProperties();     
        Context ctx = new InitialContext(prop); 
        Object ref = ctx.lookup(prop.getProperty("CRIPTOGRAFIA_LOOKUP"));       
      
        return (CriptografiaBase)PortableRemoteObject.narrow(ref, CriptografiaBase.class);
    }
	
}
